<!-- @@master  = ../../../tpl/base.html-->
<!-- @@block  =  content-->
<section class="panel panel-default">
<header class="panel-heading">
  账单明细
<span class="tools pull-right">
    <a class="fa fa-chevron-down" href="javascript:;"></a>
    <a class="fa fa-times" href="javascript:;"></a>
</span>
</header>
<div class="panel-body">
    <div class="table-box">
        <table class="display table table-bordered" id="table">
          <tr>
            <th>今日消费</th>
            <th>昨日消费</th>
            <th>7天消费</th>
            <th>30天消费</th>
            <th>余额</th>
          </tr>
        </table>
        <table class="display table table-bordered" id="order-table"></table>
    </div>
</div>
</section>
<!-- @@close-->
<!-- @@block  =  foot-->
<script type="text/javascript">
(function() {
    "use strict";
    var keys = ['today','yesterday','week','month','balance'];
    myHttp.getJSON("consume/statistics",function(data){
      var string = '<tr>'
        for(var i=0;i<keys.length;i++){
          var key = keys[i];
          if(key != "balance"){
            string += '<td>￥'+(data[key]/100).toFixed(2)+'</td>';
          }else{
            string += '<td>￥'+(data[key]/100).toFixed(2)+'    <a href="/user/recharge.html#user-recharge">充值</a></td>';
          }
        }

        string +='</tr>';
        $("#table").append(string);
    });
    var oTable = $('#order-table').dataTable({
      "bSort":false,
      "bProcessing":true,
      "bAutoWidth":false,
      "bFilter":false,
      "aoColumns": [
          {"sTitle": "操作编号","mData": "id"},
          {"sTitle": "日期","mData": "create_time"},
          {"sTitle": "付款人/公司","mData": "invoice_title"},
          {"sTitle": "发票类型","mData": "invoice_type"},
          {"sTitle": "状态","mData": "state"},
          {"sTitle": "充值金额","mData": "amount"},
      ],
      "aoColumnDefs": [
        {
          "aTargets": [ 3 ],
          "mRender": function ( data, type, full ) {
            var string = "";
            switch (data) {
              case 0:string="不开票";break;
              case 1:string="普票";break;
              case 2:string="专票";break;
            }
            return string;
          }
        },{
          "aTargets": [ 4 ],
          "mRender": function ( data, type, full ) {
            var string = "";
            switch (data) {
              case 0:string="充值审核中";break;
              case 1:string="充值成功";break;
              case 2:string="充值失败";break;
            }
            return string;
          }
        },{
          "aTargets": [ 5 ],
          "mRender": function ( data, type, full ) {
            return "￥"+(data / 100).toFixed(2);
          }
        }
      ]
    });
    // myHttp.base("../json/other/user-order.json",function(data){
    //   oTable.fnClearTable();
    //   oTable.fnAddData(data);
    // });
    myHttp.getJSON("recharge",function(data){
        if(data.list.length > 0){
          oTable.fnClearTable();
          oTable.fnAddData(data.list);
        }else{
          mygritter("查询不到数据");
        }
    },function(msg){
      console.log(msg);
    });
    // myHttp.base("../json/other/user-recharge.json",function(data){
    //   //console.log(data);
    //   if(data.list.length > 0){
    //     oTable.fnClearTable();
    //     oTable.fnAddData(data.list);
    //   }else{
    //     mygritter("查询不到数据");
    //   }
    // });
})(jQuery);
</script>
<!-- @@close-->
